<% content_for :content do %>

  <!-- widget grid -->
  <section id="widget-grid" class="">
  
    <% if current_admin.can?(controller: "admin/recommands",action: "update") %>
    <div class="row">
      <div class="col-sm-12">
        <div class="well">
          <%= simple_form_for :recommand, url: admin_recommands_path, :defaults => { :input_html => { :class => "form-control" } }, method: 'get', html: { class: "form-inline" } do |f| %>
            <label>统计模式</label>
            <%= f.input_field :group, selected: params[:recommand][:group], collection: [['推荐人', 'recommander_id'], ['终端', 'terminal_id']], label: false %>
            <div class="form-group string">            
            <%= f.text_field :start_date, class: "form-control datepicker", "data-dateformat" => "yy-mm-dd", value: params[:recommand][:start_date], placeholder: "开始时间" %>
            </div>
            <div class="form-group string">
            <%= f.text_field :end_date, class: "form-control datepicker", "data-dateformat" => "yy-mm-dd", value: params[:recommand][:end_date], placeholder: "结束时间" %>
            </div>
            <label>保级推荐数</label>
            <%= f.input_field :stay, value: params[:recommand][:stay] %>
            <label>升级推荐数</label>
            <%= f.input_field :promotion, value: params[:recommand][:promotion] %>
            <%= f.submit "预览", :class => "btn btn-default"%>
            <%= f.submit "实施", :class => "btn btn-default"%>
            <%= f.submit "自动", :class => "btn btn-default"%>
          <% end %>
        </div> <!-- end well div -->

      </div>
    </div>
    <% end %>

    <!-- row -->
    <div class="row">

      <div class="col-sm-12">
        <p class="alert alert-success"><i class="fa-fw fa fa-warning"></i> <%= @notice %></p>
      </div>

      <!-- NEW WIDGET START -->
      <article class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
        
        <!-- Widget ID (each widget will need unique ID)-->
        <div class="jarviswidget jarviswidget-color-darken" id="wid-id-1" data-widget-editbutton="false" data-widget-colorbutton="false" data-widget-deletebutton="false">
          <!-- widget options:
          usage: <div class="jarviswidget" id="wid-id-0" data-widget-editbutton="false">

          data-widget-colorbutton="false"
          data-widget-editbutton="false"
          data-widget-togglebutton="false"
          data-widget-deletebutton="false"
          data-widget-fullscreenbutton="false"
          data-widget-custombutton="false"
          data-widget-collapsed="true"
          data-widget-sortable="false"

          -->
          <header>
            <span class="widget-icon"> <i class="fa fa-table"></i> </span>
            <h2>推荐列表</h2>
          </header>

          <!-- widget div-->
          <div>

            <!-- widget edit box -->
            <div class="jarviswidget-editbox">
              <!-- This area used as dropdown edit box -->
            </div>
            <!-- end widget edit box -->

            <!-- widget content -->
            <div class="widget-body no-padding">

              <div class="alert alert-info no-margin">
                <i class="fa-fw fa fa-info"></i>共有<%= @recommands.size %>条记录
                <span class="col-md-offset">
                  <a class="btn btn-default btn-sm" href="<%= admin_recommands_path(format: :csv, recommand: params[:recommand]) %>">导出为CSV</a>
                </span>
              </div>

              <table class="table table-bordered table-striped">
                <thead>
                  <tr>
                    <% if params[:recommand][:group] == 'recommander_id' %>
                      <th>推荐人</th>
                      <th>联系方式</th>
                    <% else %>
                      <th>终端</th>
                    <% end %>
                    <th>推荐数量</th>
                    <% if @level_mode %>
                      <th>用户组级别划分</th>
                      <th>之前级别</th>
                      <th>级别变动</th>
                      <th>变化后级别</th>
                    <% end %>
                  </tr>
                </thead>
                <tbody>
                <% @recommands.each do |recommand| %>
                  <tr id='recommand-<%= recommand.send(params[:recommand][:group]) %>'>
                    <% if params[:recommand][:group] == 'recommander_id' %>
                      <th><%= recommand.recommander.name %></th>
                      <th><%= recommand.recommander.mobile_number %></th>
                    <% else %>
                      <th><%= recommand.terminal %></th>
                    <% end %>   
                    <td><%= recommand.respond_to?(:total) ? recommand.total : 0 %></td>
                    <% if @level_mode %>
                      <td><%= recommand.recommander.account_group.levels %></td>
                      <td><%= recommand.recommander.level_before %></td>
                      <td><%= recommand.recommander.level_change %></td>
                      <td><%= recommand.recommander.level_after %><%= '<strong>(已调整)<strong>'.html_safe if @adjust_mode %></td>
                    <% end %>
                  </tr>
                <% end %>
                </tbody>
              </table>
            </div>
            <!-- end widget content -->

          </div>
          <!-- end widget div -->

        </div>
        <!-- end widget -->
  
      </article>
      <!-- WIDGET END -->

    </div>
  
    <!-- end row -->

  </section>
  <!-- end widget grid -->
<% end %>